﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

/// <summary>
/// usefulClass 的摘要说明
/// </summary>
public class comUse
{
	public comUse()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
    }
    /**
     * 判断可否转换为正整数
     * 参数：strNumber要进行判断的字符串
     * 返回：是返回true,否返回false
     * */
    public static bool IsNumber(String strNumber)
    {
        Regex numberPattern = new Regex("^[0-9]+$");
        return numberPattern.IsMatch(strNumber);
    }

    public static bool IsEmail(string email)
    {
        Regex emailPattern = new Regex("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
        return emailPattern.IsMatch(email);
    }

    public static string getConnectionString() {
        return System.Configuration.ConfigurationManager.ConnectionStrings["gdsplanConnectionString"].ToString();
    }

    //计算某一天属于一年的第几周
    public int getWeek(DateTime dt)
    {
        int w = dt.DayOfYear;
        int year = dt.Year;
        DayOfWeek firstDay = DateTime.Parse(year + "-01-01").DayOfWeek;
        int theday;

        switch (firstDay)
        {
            case DayOfWeek.Monday:
                theday = 0;
                break;
            case DayOfWeek.Tuesday:
                theday = 1;
                break;
            case DayOfWeek.Wednesday:
                theday = 2;
                break;
            case DayOfWeek.Thursday:
                theday = 3;
                break;
            case DayOfWeek.Friday:
                theday = 4;
                break;
            case DayOfWeek.Saturday:
                theday = 5;
                break;
            default:
                theday = 6;
                break;
        }
        w = (w + theday - 1) / 7 + 1;
        return w;
    }

    public static bool IsOracleKeyword(string keyword)
    {
        string[] oracleKeyword ={ "ACCESS", "ADD", "ALL", "ALTER", "AND", "ANY", "AS", "ASC", "AUDIT", "BETWEEN", "BY", "CHAR", "CHECK", "CLUSTER", "COLUMN", "COMMENT", 
        "COMPRESS", "CONNECT", "CREATE", "CURRENT", "DATE", "DECIMAL", "DEFAULT", "DELETE", "DESC", "DISTINCT", "DROP", "ELSE", "EXCLUSIVE", "EXISTS", "FILE", "FLOAT", "FOR", "FROM", 
        "GRANT", "GROUP", "HAVING", "IDENTIFIED", "IMMEDIATE", "IN", "INCREMENT", "INDEX", "INITIAL", "INSERT", "INTEGER", "INTERSECT", "INTO", "IS", "LEVEL", "LIKE", "LOCK", "LONG", 
        "MAXEXTENTS", "MINUS", "MLSLABEL", "MODE", "MODIFY", "NOAUDIT", "NOCOMPRESS", "NOT", "NOWAIT", "NULL", "NUMBER", "OF", "OFFLINE", "ON", "ONLINE", "OPTION", "OR", "ORDER", "PCTFREE", 
        "PRIOR", "PRIVILEGES", "PUBLIC", "RAW", "RENAME", "RESOURCE", "REVOKE", "ROW", "ROWID", "ROWNUM", "ROWS", "SELECT", "SESSION", "SET", "SHARE", "SIZE", "SMALLINT", "START", 
        "SUCCESSFUL", "SYNONYM", "SYSDATE", "TABLE", "THEN", "TO", "TRIGGER", "UID", "UNION", "UNIQUE", "UPDATE", "USER", "VALIDATE", "VALUES", "VARCHAR", "VARCHAR2", "VIEW", "WHENEVER", 
        "WHERE", "WITH" };

        string upkeyword = keyword.Trim().ToUpper();
        for (int i = 0; i < oracleKeyword.Length; i++)
        {
            if (oracleKeyword[i] == upkeyword)
                return true;
        }
        return false;
    }

    public static string SafeAlertMsg(string str)
    {
        return str.Replace("\'", "").Replace("\r", "").Replace("\n", "\\n");
    }
}
